home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 22
/
Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso
/
Aminet
/
util
/
rexx
/
DSMiscRexxVol3.lha
/
DSMiscRexxVol3
/
NewBarGraph.dsrx
< prev
next >
Wrap
Text File
|
1997-09-12
|
13KB
|
532 lines
/* Allow commands to return results */
options results
/* On error, goto ERROR:. Comment out this line if you wish to */
/* perform your own error checking. */
signal on error
'PROJECT_LOCK'
/* BEGIN PROGRAM *************************************************/
/* +++++++++++++++++++++++++++++++++++++++ */
/* + + */
/* + Histogram drawing ARexx script V2.0 + */
/* + + */
/* + Written by Andrew Elia + */
/* + + */
/* +++++++++++++++++++++++++++++++++++++++ */
PTCNV = 28.346 /* *CONSTANT!* Converts points to Centimetres */
DATAFILE = "Dh0:T/DSMiscRexxVol3/BarDataFile" /* Full path of data file */
OFFSETX = 4.0 /* Distance between left edge of graph and the page */
OFFSETY = 3.0 /* Distance between the top edge of graph and the page */
FITSIZEX = 15 /* Width of graph */
FITSIZEY = 15 /* Height of graph */
LINEGAPX = 0.5 /* Horizontal distance between axis line and bars */
LINEGAPY = 0.5 /* Vertical distance between axis line and bars */
TICKSIZEX = 0.5 /* Height of horizontal ticks */
TICKSIZEY = 0.5 /* Length of vertical ticks */
LABELGAPX = 0.5 /* Distance between X axis labels and tick */
LABELGAPY = 0.5 /* Distance between Y axis labels and tick */
TITLEGAPX = 0.5 /* Distance between X axis title and labels */
TITLEGAPY = 0.5 /* Distance between Y axis title and labels */
YGRID = 1 /* Display grid on Y axis (turn off with 0) */
XGRID = 1 /* Display grid on X axis (turn off with 0) */
FRONTGRID = 0 /* Grid in front/behind bars (0 = Back / 1 = Front) */
COMPOUNDBARS = 1 /* Makes bars into a compound object (0 = Normal / 1 = Compound) */
GAP = 0.2 /* Inter - bar gap */
STDEV = 100 /* Standard Deviation (set to 0 for no bars) */
YMAXVAL = 1200 /* Maximum whole value */
LINESCALENUMY = 12 /* Number of ticks (not including zero) */
UNIT = "cm" /* Default measurement unit */
/* Open data file */
OK = Open('File',DATAFILE,'r')
If OK = 0 Then Do
REQ_MESSAGE TEXT '"Error: Unable to open data file"' '"Cancel"'
PROJECT_UNLOCK
Exit
End
/* Read in X and Y axis labels */
INPUT = readln('File')
GETIT = Index(INPUT,',')
GETLEN = Length(INPUT)
If GETIT ~= 0 Then Do
XAXISLABEL = Left(INPUT,GETIT - 1)
YAXISLABEL = Right(INPUT,GETLEN - GETIT)
End
Else Do
REQ_MESSAGE TEXT '"Error: Comma missing from data file (labels)"' '"Cancel"'
PROJECT_UNLOCK
Exit
End
COUNT = 0
FINISHED = 0
/* Read in data */
do while ((~eof('File')) & (Finished = 0))
INPUT = readln('File')
IF INPUT = "" Then Do
FINISHED = 1
End
Else Do
GETIT = Index(INPUT,',')
GETLEN = Length(INPUT)
If GETIT ~= 0 Then Do
COUNT = COUNT + 1
GRAPHLABEL.COUNT = Left(INPUT,GETIT - 1)
GRAPH.COUNT = Right(INPUT,GETLEN - GETIT)
End
Else Do
REQ_MESSAGE TEXT '"Error: Comma missing from data file (data)"' '"Cancel"'
PROJECT_UNLOCK
Exit
End
End
End
GSIZE = COUNT
Call Close('File')
/* Note: The way I've implemented the OFFSETX & Y handling, it's more */
/* correct to say that the offset is relative to the actual bars and not */
/* the whole graph. Therefore, OFFSETX represents the distance between */
/* the top of the tallest bar and the top of the page */
/* Search for maximum and minimum values */
MAXVALUE = GRAPH.1
MINVALUE = GRAPH.1
Do N = 1 To GSIZE
GV = GRAPH.N
If GV > MAXVALUE Then MAXVALUE = GV
If GV < MINVALUE Then MINVALUE = GV
End N
/* MINVALUE now holds the smallest value, and MAXVALUE the largest */
/* This bit works out the scale for each bar so that it will fit the */
/* sizes specified above (FITSIZEX & Y) */
SCALEY = FITSIZEY/MAXVALUE
SCALEX = (FITSIZEX - (GAP * (GSIZE - 1)))/GSIZE
/* This bit works out the distance between each vertical tick according */
/* to the scale specified by YMAXVAL, and the number of ticks specified */
/* by LINESCALENUMY. It also sets up the starting point for the first */
/* tick (COUNTICK) */
LINESCALEY = (YMAXVAL * SCALEY)/LINESCALENUMY
COUNTICK = OFFSETX + LINEGAPX
XTICKNUM = 0
XTEXTNUM = 0
YGRIDNUM = 0
/* Draws the ticks along the X axis */
REDRAW_OFF
Y1 = OFFSETY + FITSIZEY + LINEGAPY
Y2 = OFFSETY + FITSIZEY + LINEGAPY + TICKSIZEY
Y3 = Y2 + LABELGAPX
Y4 = OFFSETY + FITSIZEY - ((LINESCALENUMY + 1) * LINESCALEY)
Do N = 1 To GSIZE
X1 = COUNTICK + (SCALEX/2)
X2 = X1
CREATE_LINE X1||UNIT||" "||Y1||UNIT||" "||X2||UNIT||" "||Y2||UNIT
XTICKNAMES.XTICKNUM = RESULT
XTICKNUM = XTICKNUM + 1
If YGRID = 1 Then Do
CREATE_LINE X1||UNIT||" "||Y1||UNIT||" "||X2||UNIT||" "||Y4||UNIT
YGRIDNAMES.YGRIDNUM = RESULT
YGRIDNUM = YGRIDNUM + 1
End
OBJECT_DESELECT
'CREATE_TEXT '||X1||UNIT||' '||Y3||UNIT||' "'||GRAPHLABEL.N||'"'
XTEXTNAMES.XTEXTNUM = RESULT
XTEXTNUM = XTEXTNUM + 1
ATTRS_TEXT_SET FONT "Rocket" SIZE "24"
OBJECT_ROTATE ANGLE "270"
OBJECT_SPECS_GET STEM 'OBJSPECS.'
DIFX = X1 - (OBJSPECS.LEFT / PTCNV)
DIFX = DIFX + (((OBJSPECS.WIDTH / 2) / PTCNV) * -1)
'OBJECT_MOVE X '||DIFX||UNIT
COUNTICK = COUNTICK + SCALEX + GAP
End N
/* Groups gridlines together */
If YGRID = 1 Then Do
OBJECT_DESELECT
Do N = 0 To YGRIDNUM - 1
OBJECT_SELECT YGRIDNAMES.N
End
OBJECT_GROUP
YGRIDOBJECT = RESULT
End
/* Aligns and groups labels together */
OBJECT_DESELECT
Do N = 0 To XTEXTNUM - 1
OBJECT_SELECT XTEXTNAMES.N
End
OBJECT_ALIGN ALIGN_Y TOP
OBJECT_GROUP
OBJECT_SPECS_GET STEM 'OBJSPECS.'
DIFY = Y3 - (OBJSPECS.TOP / PTCNV)
'OBJECT_MOVE Y '||DIFY||UNIT
OBJECT_SPECS_GET STEM 'OBJSPECS.'
LABELSBOTTOM = (OBJSPECS.BOTTOM / PTCNV) + TITLEGAPX
'CREATE_TEXT '||X1||UNIT||' '||Y3||UNIT||' "'||XAXISLABEL||'"'
OBJECT_SPECS_GET STEM 'OBJSPECS.'
DIFX = (OFFSETX + LINEGAPX) - (OBJSPECS.LEFT / PTCNV) + (((FITSIZEX + LINEGAPX) - (OBJSPECS.WIDTH / PTCNV)) / 2)
DIFY = LABELSBOTTOM - (OBJSPECS.TOP / PTCNV)
'OBJECT_MOVE X '||DIFX||UNIT||' Y '||DIFY||UNIT
REDRAW_ON
/* Draws the ticks along the Y axis */
REDRAW_OFF
YTICKNUM = 0
YTEXTNUM = 0
XGRIDNUM = 0
OBJECT_DESELECT
AXISTEXTSCALE = YMAXVAL / LINESCALENUMY
X1 = OFFSETX - LINEGAPX
X2 = OFFSETX + TICKSIZEX - LINEGAPX
X3 = X1 - LABELGAPY
X4 = OFFSETX + FITSIZEX + LINEGAPX
COUNTICK = OFFSETY + FITSIZEY
Do N = 0 To LINESCALENUMY
REDRAW_OFF
Y1 = COUNTICK
Y2 = Y1
CREATE_LINE X1||UNIT||" "||Y1||UNIT||" "||X2||UNIT||" "||Y2||UNIT
YTICKNAMES.YTICKNUM = RESULT
YTICKNUM = YTICKNUM + 1
If XGRID = 1 Then Do
CREATE_LINE X2||UNIT||" "||Y1||UNIT||" "||X4||UNIT||" "||Y2||UNIT
XGRIDNAMES.XGRIDNUM = RESULT
XGRIDNUM = XGRIDNUM + 1
End
OBJECT_DESELECT
YVTXT = AXISTEXTSCALE * N
'CREATE_TEXT '||X3||UNIT||' '||Y1||UNIT||' "'||YVTXT||'"'
YTEXTNAMES.YTEXTNUM = RESULT
YTEXTNUM = YTEXTNUM + 1
OBJECT_SPECS_GET STEM 'OBJSPECS.'
DIFY = Y1 - (OBJSPECS.TOP / PTCNV)
DIFY = DIFY + (((OBJSPECS.HEIGHT / 2) / PTCNV) * -1)
'OBJECT_MOVE Y '||DIFY||UNIT
COUNTICK = COUNTICK - LINESCALEY
End N
/* Groups gridlines together */
If XGRID = 1 Then Do
OBJECT_DESELECT
Do N = 0 To XGRIDNUM - 1
OBJECT_SELECT XGRIDNAMES.N
End
OBJECT_GROUP
XGRIDOBJECT = RESULT
End
OBJECT_DESELECT
If YGRID = 1 Then Do
OBJECT_SELECT YGRIDOBJECT
GRIDOBJECT = RESULT
End
If XGRID = 1 Then Do
OBJECT_SELECT XGRIDOBJECT
GRIDOBJECT = RESULT
End
If (XGRID = 1) & (YGRID = 1) Then Do
OBJECT_GROUP
GRIDOBJECT = RESULT
End
/* Aligns and groups values together */
OBJECT_DESELECT
Do N = 0 To YTEXTNUM - 1
OBJECT_SELECT YTEXTNAMES.N
End
OBJECT_ALIGN ALIGN_X RIGHT
OBJECT_GROUP
OBJECT_SPECS_GET STEM 'OBJSPECS.'
DIFX = X3 - (OBJSPECS.RIGHT / PTCNV)
'OBJECT_MOVE X '||DIFX||UNIT
OBJECT_SPECS_GET STEM 'OBJSPECS.'
LABELSSIDE = (OBJSPECS.LEFT / PTCNV) - TITLEGAPY
OBJECT_DESELECT
'CREATE_TEXT '||X1||UNIT||' '||Y3||UNIT||' "'||YAXISLABEL||'"'
OBJECT_ROTATE ANGLE "270"
OBJECT_ALIGN TOPAGE ALIGN_X LEFT ALIGN_Y TOP
OBJECT_SPECS_GET STEM 'OBJSPECS.'
DIFX = LABELSSIDE - (OBJSPECS.RIGHT / PTCNV)
DIFY = (OFFSETY + FITSIZEY - ((LINESCALENUMY + 1) * LINESCALEY)) - (OBJSPECS.TOP / PTCNV)
DIFY = DIFY + (((LINEGAPY + ((LINESCALENUMY + 1) * LINESCALEY)) - (OBJSPECS.HEIGHT / PTCNV)) / 2)
'OBJECT_MOVE X '||DIFX||UNIT||' Y '||DIFY||UNIT
REDRAW_ON
/* Draws the horizontal and vertical axis lines */
REDRAW_OFF
X1 = OFFSETX
X2 = OFFSETX + FITSIZEX + LINEGAPX
Y1 = OFFSETY + FITSIZEY - ((LINESCALENUMY + 1) * LINESCALEY)
Y2 = OFFSETY + LINEGAPY + FITSIZEY
CREATE_BEZIER X1||UNIT||" "||Y1||UNIT||" L "||X1||UNIT||" "||Y2||UNIT||" L "||X2||UNIT||" "||Y2||UNIT
AXISNAME = RESULT
/* Groups axis and ticks together */
OBJECT_DESELECT
OBJECT_SELECT AXISNAME
Do N = 0 To XTICKNUM - 1
OBJECT_SELECT XTICKNAMES.N
End
Do N = 0 To YTICKNUM - 1
OBJECT_SELECT YTICKNAMES.N
End
OBJECT_GROUP
BOTHAXISNAME = RESULT
ATTRS_PENSTYLE_SET START "None" END "None" JOIN "Round" THICKNESS "1mm"
ATTRS_PENCOLOUR_SET 0 0 0 0
ATTRS_PENFILL_SET "Solid" "Black"
ATTRS_FILLFILL_SET "None" "Black"
OBJECT_TOFRONT
OFFSETX = OFFSETX + LINEGAPX
REDRAW_ON
/* Draws the actual bars */
/* Also checks that if the size of the bar is zero -don't bother */
/* drawing it. This bit can always be taken out if you want a very */
/* small line to be drawn instead */
REDRAW_OFF
BARNUM = 0
EBARNUM = 0
COUNTBAR = OFFSETX
Do N = 1 To GSIZE
X1 = COUNTBAR
X2 = COUNTBAR + SCALEX
Y1 = OFFSETY + ((MAXVALUE * SCALEY) - (GRAPH.N * SCALEY))
Y2 = OFFSETY + (MAXVALUE * SCALEY)
If (Y1 - Y2) ~= 0 Then Do
OBJECT_DESELECT
CREATE_RECT X1||UNIT||" "||Y1||UNIT||" "||X2||UNIT||" "||Y2||UNIT
BARNAMES.BARNUM = RESULT
BARNUM = BARNUM + 1
ATTRS_PENSTYLE_SET START "None" END "None" JOIN "Round" THICKNESS "1mm"
ATTRS_PENCOLOUR_SET 0 0 0 0
ATTRS_PENFILL_SET "Solid" "Black"
ATTRS_FILLFILL_SET "Solid" '"Pure Red"'
ATTRS_FILLCOLOUR_SET 255 0 0 255
If STDEV ~= 0 Then Do
Y3 = OFFSETY + ((MAXVALUE * SCALEY) - ((GRAPH.N + STDEV) * SCALEY))
CREATE_LINE X1||UNIT||" "||Y3||UNIT||" "||X2||UNIT||" "||Y3||UNIT
LB1 = RESULT
Y4 = OFFSETY + ((MAXVALUE * SCALEY) - ((GRAPH.N - STDEV) * SCALEY))
CREATE_LINE X1||UNIT||" "||Y4||UNIT||" "||X2||UNIT||" "||Y4||UNIT
LB2 = RESULT
X3 = X1 + ((X2 - X1) / 2)
CREATE_LINE X3||UNIT||" "||Y3||UNIT||" "||X3||UNIT||" "||Y4||UNIT
LB3 = RESULT
OBJECT_DESELECT
OBJECT_SELECT LB1
OBJECT_SELECT LB3
OBJECT_JOIN
OBJECT_SELECT LB2
OBJECT_JOIN
OBJECT_SPECS_GET STEM 'OBJSPECS.'
XP = OBJSPECS.LEFT / PTCNV
YP = OBJSPECS.TOP / PTCNV
CUT
PASTE XP YP
OBJECT_SPECS_GET STEM 'OBJSPECS.'
EBARNAME.EBARNUM = OBJSPECS.NAME
EBARNUM = EBARNUM + 1
ATTRS_PENSTYLE_SET START "None" END "None" JOIN "Round" THICKNESS "1mm"
ATTRS_PENCOLOUR_SET 0 0 0 0
ATTRS_PENFILL_SET "Solid" "Black"
ATTRS_FILLFILL_SET "None" "Black"
End
End
COUNTBAR = COUNTBAR + SCALEX + GAP
End N
/* Selects all the bars */
OBJECT_DESELECT
Do N = 0 To BARNUM - 1
OBJECT_SELECT BARNAMES.N
End
ATTRS_PENSTYLE_SET START "None" END "None" JOIN "Round" THICKNESS "1mm"
ATTRS_PENCOLOUR_SET 0 0 0 0
ATTRS_PENFILL_SET "Solid" "Black"
ATTRS_FILLFILL_SET "Solid" '"Pure Red"'
ATTRS_FILLCOLOUR_SET 255 0 0 255
/* Makes the bars either a group object or a compound object*/
If COMPOUNDBARS = 0 Then Do
OBJECT_GROUP
End
Else Do
OBJECT_MAKE_COMPOUND
End
OBJECT_TOBACK
If EBARNUM > 0 Then Do
OBJECT_DESELECT
Do N = 0 To EBARNUM - 1
OBJECT_SELECT EBARNAME.N
End
OBJECT_GROUP
ATTRS_PENSTYLE_SET START "None" END "None" JOIN "Round" THICKNESS "1mm"
ATTRS_PENCOLOUR_SET 0 0 0 0
ATTRS_PENFILL_SET "Solid" "Black"
ATTRS_FILLFILL_SET "None" "Black"
End
/* Puts the grid in front of or behind the bars */
OBJECT_DESELECT
OBJECT_SELECT GRIDOBJECT
If FRONTGRID = 0 Then Do
OBJECT_TOBACK
End
Else Do
OBJECT_TOFRONT
OBJECT_DESELECT
OBJECT_SELECT BOTHAXISNAME
OBJECT_TOFRONT
End
/* Ta da! */
REDRAW_ON
/* END PROGRAM ***************************************************/
PROJECT_UNLOCK
Exit
/* On ERROR */
ERROR:
'PROJECT_UNLOCK'
/* If we get here, either an error occurred with the command's */
/* execution or there was an error with the command itself. */
/* In the former case, rc2 contains the error message and in */
/* the latter, rc2 contains an error number. SIGL contains */
/* the line number of the command which caused the jump */
/* to ERROR: */
if datatype(rc2,'NUMERIC') == 1 then do
/* See if we can describe the error with a string */
select
when rc2 == 103 then
err_string = "ERROR 103, "||,
"out of memory at line "||SIGL
when rc2 == 114 then
err_string = "ERROR 114, "||,
"bad command template at line "||SIGL
when rc2 == 115 then
err_string = "ERROR 115, "||,
"bad number for /N argument at line "||SIGL
when rc2 == 116 then
err_string = "ERROR 116, "||,
"required argument missing at line "||SIGL
when rc2 == 117 then
err_string = "ERROR 117, "||,
"value after keywork missing at line "||SIGL
when rc2 == 118 then
err_string = "ERROR 118, "||,
"wrong number of arguments at line "||SIGL
when rc2 == 119 then
err_string = "ERROR 119, "||,
"unmatched quotes at line "||SIGL
when rc2 == 120 then
err_string = "ERROR 120, "||,
"line too long at line "||SIGL
when rc2 == 236 then
err_string = "ERROR 236, "||,
"unknown command at line "||SIGL
otherwise
err_string = "ERROR "||rc2||", at line "||SIGL
end
end
else if rc2 == 'RC2' then do
err_string = "ERROR in command at line "||SIGL
end
else do
err_string = rc2||", line "||SIGL
end
req_message TEXT '"'err_string'"'
exit